/*
 * @Author: C.
 * @Date: 2023-12-04 11:54:33
 */
import { getCurrentInstance, inject } from 'vue'
import { indexPageContextKey } from '../web/useHomePage'
type OnLoadFunction = () => void
type OnShowFunction = () => void

export const useIndexPageProvide = (
  name: string,
  onShow: OnShowFunction,
  onLoad: OnLoadFunction,
  onHide: OnShowFunction
) => {
  const instance = getCurrentInstance()
  const { uid } = instance!

  const indexPage = inject(indexPageContextKey, null)

  indexPage?.addItem({
    name,
    uid,
    onShow,
    onLoad,
    onHide,
  })
}

export const useIndexPage = () => {
  // 处理当前页面显示时的事件
  const onShow = () => {
    /** empty */
    console.log('ddd')
  }

  // 处理当前页面加载时的事件
  const onLoad = () => {
    /** empty */
  }
  useIndexPageProvide('basic', onShow, onLoad)
}
